<?php
namespace app\fsadmin\controller;

use think\auth\Auth;
use think\Controller;

/**
 *
 */
class BaseController extends Controller
{

    public function _initialize()
    {
        if (!session('?admin')) {
            if ($this->request->isAjax()) {
                $msg['status'] = 401;
                $msg['msg']    = "请登录后操作";
                ajax_return($msg);
            } else {
                echo "<script>top.window.location='" . url("login/index") . "'</script>";
            }
        }

        $module     = $this->request->module();
        $controller = lcfirst(request()->controller());
        $action     = request()->action();

        if ($controller != "index" && $action != "index") {
            $auth = new Auth();
            if (!$auth->check($module . '-' . $controller . '-' . $action, session('admin')["id"])) {
                if ($this->request->isAjax()) {
                    ajax_return(["msg" => "你没有权限访问"]);
                } else {
                    $this->error("你没有权限访问", "");
                }
            }
        }

    }
}
